﻿using LineStickerDwonload.Helper;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Net;
using CatUtils.Utils.Currency.IoUtils;
using CatUtilsDll.Utils.Currency.WebUtils;
using LineStickerDwonload.Linehelper;
using CatUtils.Utils.Currency;
using System.Collections.Generic;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.TypeConvert;
using CatUtils.Utils.Helper;
using LineStickerDwonload.Linehelper.ApngTool;

namespace LineStickerDwonload
{
    public partial class MainView : Form
    {
        public MainView()
        {
            InitializeComponent();
            FloderHelper.FloderExits(LineStaticValue.TempPath, true);
            Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            FloderHelper.InitFloder();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.IndexOf("store.line.me/stickershop") >= 0)
                Linehelper.Scanner.StartAsycn(textBox1.Text);
            else
                MessageBox.Show("仅支持store.line.me/stickershop/product/类的链接");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(LineStaticValue.TempPath);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //    WebHelper.ImgDownload(".\\ca\\", "https://stickershop.line-scdn.net/stickershop/v1/sticker/27243864/android/sticker.png", DownStringCompletedCallBack, ProgressCountCallBack);
        }

        private void DownStringCompletedCallBack(object sender, AsyncCompletedEventArgs e)
        {
            Console.WriteLine("下载完成");
        }

        private void ProgressCountCallBack(object sender, DownloadProgressChangedEventArgs e)
        {
            Console.WriteLine("进度" + e.ProgressPercentage);
        }

        private bool Firstentry = true;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (LineStaticValue.LockProgress)
            {
                if (Firstentry)
                {
                    label2.Text = "已开始下载";
                    progressBar1.Maximum = LineStaticValue.MaxProgress;
                    LineStaticValue.Tip = "任务全部完成！";
                    Firstentry = false;
                }
                if (LineStaticValue.CurrentProgress < progressBar1.Maximum)
                    progressBar1.Value = LineStaticValue.CurrentProgress;
            }
            else
            {
                if (!Firstentry)
                {//反向锁住更新UI
                    progressBar1.Value = 0;
                    Firstentry = true;
                    textBox1.Text = "";
                }
                label2.Text = LineStaticValue.Tip;
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://acg12.com/");
        }

        private void label7_Click(object sender, EventArgs e)
        {
            OpenCatBlog();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenCatBlog();
        }

        private void OpenCatBlog()
        {
            System.Diagnostics.Process.Start("http://www.acg12.net/?p=6810");
        }

        private void label8_Click(object sender, EventArgs e)
        {
            OpenCatBlog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            new ExcavateScanner().AutoSvae(textBox1.Text, TextHelper.StringToInt(textBox2.Text));
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            string FilepATH = FileHelper.SelectFile();
            if (FilepATH == "")
                return;
            string Content = new HexConvert().FileToHex(FilepATH);

            FileHelper.WriteText("text.txt", Content);
        }

        private void button4_Click_2(object sender, EventArgs e)
        {
            new ApngTool().ShowDialog();
        }
    }
}